#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 60;
int a[N];
ll ans;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		ans = 0;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a + n);
		for (int i = 0; i < n / 2; i++)
			ans += abs(a[n - i - 1] - a[i]);
		cout << ans << endl;
	}
	return 0;
}